package com.theme.passport.controller.trade;

import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.view.R;
import com.theme.passport.entity.theme.UserBuyEntity;
import com.theme.passport.service.theme.UserBuyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 用户已购主题
 *
 * @author live
 * @email 870459550@qq.com
 * @date 2023-03-29 13:56:31
 */
@RestController
@RequestMapping("trade/user-buy")
public class UserBuyController {
    @Autowired
    private UserBuyService tabUserBuyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("trade:user-buy:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tabUserBuyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("trade:user-buy:info")
    public R info(@PathVariable("id") Long id){
		UserBuyEntity userBuy = tabUserBuyService.getById(id);

        return R.ok().put("userBuy", userBuy);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("trade:user-buy:save")
    public R save(@RequestBody UserBuyEntity tabUserBuy){
        tabUserBuy.setCreated(new Date());
		tabUserBuyService.save(tabUserBuy);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("trade:user-buy:update")
    public R update(@RequestBody UserBuyEntity tabUserBuy){
        tabUserBuy.setUpdated(new Date());
		tabUserBuyService.updateById(tabUserBuy);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("trade:user-buy:delete")
    public R delete(@RequestBody Long[] ids){
		tabUserBuyService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
